

package com.maoshi.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.config.Constant;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.distribution.comment.model.DistributionUserIncome;
import com.maoshi.shop.distribution.comment.param.RangeTimeParam;
import com.maoshi.shop.distribution.comment.service.DistributionUserIncomeService;
import com.maoshi.shop.security.platform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionUserIncome")
public class DistributionUserIncomeController {

    @Autowired
    private DistributionUserIncomeService distributionUserIncomeService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:page')")
    public ResponseEntity<IPage<DistributionUserIncome>> page(DistributionUserIncome distributionUserIncome, PageParam<DistributionUserIncome> page) {
        IPage<DistributionUserIncome> list = distributionUserIncomeService.page(page, new LambdaQueryWrapper<DistributionUserIncome>());
        return ResponseEntity.ok(list);
    }

    /**
     * 分页获取
     */
    @GetMapping("/page/anduser")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:page')")
    public ResponseEntity<IPage<DistributionUserIncome>> page(PageParam<DistributionUserIncome> page,
                                                              RangeTimeParam rangeTimeParam
            , String userMobile
            , String orderNumber
    ) {
        IPage<DistributionUserIncome> list = distributionUserIncomeService.incomeAndDistributionUserPage(page, Constant.PLATFORM_SHOP_ID, rangeTimeParam, userMobile, orderNumber);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:info')")
    public ResponseEntity<DistributionUserIncome> info(@PathVariable("id") Long id) {
        DistributionUserIncome distributionUserIncome = distributionUserIncomeService.getById(id);
        return ResponseEntity.ok(distributionUserIncome);
    }

    /**
     * 保存
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid DistributionUserIncome distributionUserIncome) {
        distributionUserIncomeService.save(distributionUserIncome);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionUserIncome distributionUserIncome) {
        distributionUserIncomeService.updateById(distributionUserIncome);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionUserIncomeService.removeById(id);
        return ResponseEntity.ok().build();
    }
}
